﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication2.CLASS;
using System.Data.SqlClient;
using System.Collections;

namespace WindowsFormsApplication2
{ 
    public partial class frmRegCustomer : Form
    {
        private SqlConnection conn;
        string _cusId = "";
        public enum clicktype
        {
            Add = 1,
            Edit = 2,

        }
        clicktype ConsructorType = new clicktype();

        public frmRegCustomer(SqlConnection co)
        {
            InitializeComponent();
            ConsructorType = clicktype.Add;
            
            conn = co;
        }
         public frmRegCustomer(Customer _cust) 
        {
            ConsructorType = clicktype.Edit;
            InitializeComponent();
            //_cusId = _cust.CustomerId;
            cusFname.Text = _cust.CustomerFName;
            cusLname.Text = _cust.CustomerLName;
            cusRd.Text = _cust.CustomerRd;
            cusaddress.Text = _cust.CustomerAddress;
            cusphone.Text = _cust.CustomerPhone;
            xtolologch.Text = _cust.XTolologchId;
            cuspass.Text = _cust.CustomerPass;
             
        }
        
         
        private void btnXTback_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnXTadd_Click(object sender, EventArgs e)
        {
            if (ConsructorType == clicktype.Add)
            {
                Customer.AddFunction(_cusId, cusFname.Text, cusLname.Text, cusRd.Text, cusaddress.Text, cusphone.Text, xtolologch.Text,cuspass.Text);
                MessageBox.Show("Нэмэх үйлдэл");
                frmCustomer frm = new frmCustomer(conn);
                frm.dataGridViewCustomer.DataSource = DBTools.selecQryTmp("Select *from Customers");
            }
            else
            {

                Customer.EditFunction(_cusId, cusFname.Text, cusLname.Text, cusRd.Text, cusaddress.Text, cusphone.Text, xtolologch.Text, cuspass.Text);
                MessageBox.Show("Засах үйлдэл");
                frmCustomer frm = new frmCustomer(conn);
                frm.dataGridViewCustomer.DataSource = DBTools.selecQryTmp("Select *from Customers");

            }
            this.Close();
        }

        private void frmRegAddCustomer_Load(object sender, EventArgs e)
        {
            DataTable tmp = new DataTable();
            tmp = DBTools.selecQryTmp("Select *from XTolologch");
            dataGridView1.DataSource = tmp;
            //this.DataGridView1.Columns["zurag"].ValueType = typeof(Image);
            xtolologch.DataSource = tmp;

            xtolologch.DisplayMember = "XTolologchId";
            xtolologch.ValueMember = "";

            
        }

        

       

        

       

       
    }
}
